# coding=utf-8
from django import template
from  datetime import datetime
register = template.Library()


# 判断时间差, 过滤器
@register.filter(name='cut')
def cut(value):
    date1 = datetime.now().timestamp()
    date2 = value.timestamp()
    date = date1 - date2
    if date > 60 and date / 60 < 60:
        return str(round(date/60)) + '分钟前'
    elif date / 60 > 60 and date / 3600 < 24:
        return str(round(date/3600)) + '小时前'
    elif date / 3600> 24 and date / 3600 / 24 < 30:
        return str(round(date/3600/24)) + '天前'
    elif date / 3600 /24 >30 and date / 3600 / 24 / 30 < 12:
        return str(round(date/3600/24/30)) + '月前'
    else:
        return '刚刚'


register.filter('minus', cut)
